<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Participer à un event</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="media/css/styleRechercheAvance.css"
	type="text/css" />
</head>
<body>
	<h1>Recherche Avancée</h1>
	<form method="post" action="index.php?page=rechercheAvance">
		<div id='dated'>
			<label class="dateDebut" for="dateDebut"> Date de début :</label> <input
				type="date" name="dateDeb " id="datedebut" /> <label class="lieu"
				for='lieu'> Lieu : </label> <input type='text' name='adresse'
				id='lieu' /> <label class='ageMinimum' for='ageMinimum'> Age minimum requis
				: </label> <input type="number" name='ageMin' id='ageMin' min='0'
				step='1'>
		</div>
		<br /> <br />
		<div id='datef'>
			<label class="dateFin" for="dateFin"> Date de fin :</label> <input
				type="date" name="dateFin " id="dateFin" /> <label class="ville"
				for='ville'> Ville : </label><input type='text' name='ville'
				id='ville' /> <label for="theme" class='theme'>Thèmes :</label> <select
				name="theme" id="theme">
				<optgroup label="thème">
					<option value="Gastronomie">Gastronomie</option>
					<option value="Musique">Musique</option>
					<option value="Culture">Culture</option>
					<option value="Sports">Sport</option>
					<option value="Soirées">Soirées</option>
					<option value="Autres">Autres...</option>
				</optgroup>
			</select>
		</div>
		<br /> <br />
		<div id='recherche1'>
			<label for="recherche1">Recherche : </label><input type="text"
				id='rechercher' name="requete" autocomplete="off"
				placeholder="nom,date,description..." /> <input type="submit" />
	
	</form>
	</div>
	<br />
	<br />
	<h1>Résultats de la recherche</h1>


	<?php


	if (isset($_POST['ville'])||(isset($_POST['adresse'])) || (isset($_POST['theme'])) ||  (isset($_POST['ageMin'])) ||  (isset($_POST['dateDeb'])) ||  (isset($_POST['dateFin'])))
	{

		$requete = $_POST['requete'];
		$theme = $_POST['theme'];
		$ville = $_POST['ville'];
		$adresse = $_POST['adresse'];
		$ageMin = $_POST['ageMin'];
		$dateDeb = $_POST['dateDeb'];
		$dateFin = $_POST['dateFin'];

		$req = $bdd->prepare("SELECT * FROM event WHERE ville LIKE '%$ville%' AND  adresse LIKE'%$adresse%' AND theme LIKE'%$theme%' AND requete LIKE '%$requete%' AND  ageMin LIKE '%$ageMin%' AND  dateDeb LIKE '%$dateDeb%' AND  dateFin '%$dateFin%'");
		$req->execute(array());

		$nb_resultats = $req->rowCount();

		if($nb_resultats != 0){
?>
	<div id='resultats'>
		<p>
			Nous avons trouvé
			<?php echo $nb_resultats; 
			if($nb_resultats > 1) {
echo ' résultats';
} else { echo ' résultat';
}
?>
			à votre recherche :
	
	</div>
	<br />

	<?php
	while($donnees = $req->fetch())
	{
		?>

	<div class="recherchex">

		<div id='nom'>
			Nom de l'event : <a
				href="desc_event.php?id=<?php echo $donnees['id'];?>"><?php echo $donnees['nom']; ?>
			</a>
		</div>
		<div id='date'>
			<?php echo $donnees['date']; ?>
		</div>
		<br />
		<?php echo $donnees['description']; ?>
		<br />
		<?php
	}
	?>
		<?php
}
else
{
	?>

		<p>
			Aucun resultat ne correspond à votre recherche "
			<?php echo $_POST['requete']; ?>
			". <a href="index.php?page=rechercheAvance">Réessayez...</a>avec
		  de nouveaux mots clefs.
		</p>
		<?php
}
$req->closeCursor();
	}
	else
	{
		?>
		<?php
	}
?>